package com.CityHunter.OverLay;

import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.widget.Toast;

import com.CityHunter.Friend;
import com.CityHunter.FriendList;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class FriendOl extends Overlay {

	FriendList fl;
	Friend fd;
	String myname;

	public FriendOl(FriendList fl) {
		this.fl = fl;
		

	}

	public void draw(Canvas canvas, MapView mv, boolean shadow) {

		super.draw(canvas, mv, shadow);

		while (fl.hasNext()) {
			
			fd = fl.Next();
		
			
			Paint p = new Paint();
			int[] scoords = new int[2];
			int sz = 5;

			Point myScreenCoords = new Point();
			mv.getProjection().toPixels(fd.getPosition(), myScreenCoords);

			// Draw point caption and its bounding rectangle
			scoords[0] = myScreenCoords.x;
			scoords[1] = myScreenCoords.y;
			p.setTextSize(14);
			p.setAntiAlias(true);

			int sw = (int) (p.measureText(String.valueOf(fd.getLatitude())) + 0.5f);
			int sh = 25;
			int sx = scoords[0] - sw / 2 - 5;
			int sy = scoords[1] - sh - sz - 2;
			RectF rec = new RectF(sx, sy, sx + sw + 10, sy + sh);

			p.setStyle(Style.FILL);
			p.setARGB(128, 255, 0, 0);

			canvas.drawRoundRect(rec, 5, 5, p);

			p.setStyle(Style.STROKE);
			p.setARGB(255, 255, 255, 255);
			canvas.drawRoundRect(rec, 5, 5, p);
			// canvas.d

			canvas.drawText(fd.getName(), sx + 5, sy + sh - 8, p);

			// Draw point body and outer ring
			p.setStyle(Style.FILL);
			p.setARGB(88, 255, 0, 0);
			p.setStrokeWidth(1);
			RectF spot = new RectF(scoords[0] - sz, scoords[1] + sz, scoords[0]
					+ sz, scoords[1] - sz);
			canvas.drawOval(spot, p);

			p.setARGB(255, 255, 0, 0);
			p.setStyle(Style.STROKE);
			canvas.drawCircle(scoords[0], scoords[1], sz, p);
			
		}
	}
}
